package com.wei.czz.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;

/**
 * Created by IntelliJ IDEA.
 *
 * @author wei
 * date: 2022-01-21 10:34:00
 * className: HttpConfig http请求配置类
 * version: 1.0
 * description:
 */
@Configuration
public class HttpConfig {

    @Bean
    public RestTemplate restTemplate() {
        /*HttpComponentsClientHttpRequestFactory httpComponentsClientHttpRequestFactory = new HttpComponentsClientHttpRequestFactory();
        // 设置连接超时时间
        httpComponentsClientHttpRequestFactory.setConnectTimeout(5_000);
        // 设置数据读取超时时间
        httpComponentsClientHttpRequestFactory.setReadTimeout(30_000);
        // 封装http请求客户端
        HttpClient httpClient = HttpClientBuilder.create().setMaxConnTotal(200).setMaxConnPerRoute(200).build();
        // 设置http请求客户端
        httpComponentsClientHttpRequestFactory.setHttpClient(httpClient);

        return new RestTemplate(httpComponentsClientHttpRequestFactory);*/
        /**
         * 简单请求客户端
         *
         */
        SimpleClientHttpRequestFactory simpleClientHttpRequestFactory = new SimpleClientHttpRequestFactory();
        simpleClientHttpRequestFactory.setConnectTimeout(5_000);
        simpleClientHttpRequestFactory.setReadTimeout(30_000);
        return new RestTemplate(simpleClientHttpRequestFactory);
    }
}
